package com.fu.web.controler;

import com.alibaba.fastjson.JSON;
import com.fu.web.DTO.chargeForming;
import com.fu.web.DTO.docLabel;
import com.fu.web.DTO.payVue;
import com.fu.web.DTO.registerVue;
import com.fu.web.entity.departments;
import com.fu.web.entity.registerForm;
import com.fu.web.service.menuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/menuControl")
public class menuControl {
    @Autowired
    private menuService menuService;

    @PostMapping("addRegister")
    public int addRegister(@RequestBody registerVue registerVue){
        registerForm registerForm=new registerForm();
        menuService.addRegisterForm(registerForm,registerVue);

        return 1;

    }

    @GetMapping("/showLabel")
    public @ResponseBody String showLabel(){
        List<docLabel> doctors = new ArrayList<docLabel>();
        List<departments> list=new ArrayList<departments>();
        List<ArrayList> finalList=new ArrayList<ArrayList>();

        doctors=menuService.showDoc();
        list=menuService.showDe();
        finalList.add((ArrayList) doctors);
        finalList.add((ArrayList) list);
        String json= JSON.toJSONString(finalList);
        return  json;
    }

    @PostMapping("/payOvered")
    public @ResponseBody String payOvered (@RequestBody chargeForming chargeForming){
        payVue payVue = menuService.payTotalCost(chargeForming.getChargeId());
        if(payVue!=null){
            String json=JSON.toJSONString(payVue);
            return json;
        }
        else{
            return "";
        }

    }
}
